#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int left = 0, right = 0, zeronums = 0, len = 0;
        while (right < nums.size())
        {
            if (nums[right] == 0) zeronums++;
            while (zeronums > k)
            {
                if (nums[left++] == 0)
                    zeronums--;
            }
            len = max(len, right - left + 1);
            right++;
        }
        return len;
    }
};